//
//  AXFFootView.m
//  BEEQUICK
//
//  Created by 李典 on 16/11/22.
//  Copyright © 2016年 SevenGroup. All rights reserved.
//

#import "AXFFootView.h"

@interface AXFFootView ()

@property (weak, nonatomic) IBOutlet UIButton *selectBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;


@end

@implementation AXFFootView
static id _instance;
+ (instancetype) shareFootView
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc]init];
    });
    return _instance;
    
}

- (instancetype)init
{
    if (self = [super init]) {
        
        return [[[NSBundle mainBundle] loadNibNamed:@"AXFFootView" owner:nil options:nil] lastObject];
    }
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    //选择按钮
    [self.selectBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    //默认对号按钮加载时选中状态
    self.rightBtn.selected = YES;
    
    
}

#pragma mark - 改变对号按钮的状态
- (void)changeRightBtnWithManger:(AXFModelManager *)manger{

    
    self.rightBtn.selected = manger.btnArrayselect;



}

//点击✅
- (IBAction)rightAction:(UIButton *)sender {
    
    sender.selected = !self.rightBtn.selected;
    
    [[AXFModelManager shareModelManager].managerModelList enumerateObjectsUsingBlock:^(AXFDetailsModel* obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        obj.btnSelect = sender.selected;
        
    }];
    
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshList" object:self];
    
    
    
    if ([self.delegate respondsToSelector:@selector(AXFFootView:withAllRightBtn:)]) {
        [self.delegate AXFFootView:self withAllRightBtn:sender];
    }
    
}


- (void)setModel:(NSArray<AXFDetailsModel *> *)model
{
    _model = model;
     float total;
    
    total = [[AXFModelManager shareModelManager] showTotalPrice];
    self.totalPrice.text = [NSString stringWithFormat:@"共¥ %.2lf",total];
    
}
//添加选好了按钮的点击事件
- (void)btnClick:(UIButton *)sender
{
    if ([_delegate respondsToSelector:@selector(pushToPayController)]) {
        
        [_delegate pushToPayController];
    }
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
